package anthology.leet_code_hot;

import java.util.List;

//https://leetcode.cn/problems/minimum-right-shifts-to-sort-the-array/description/
public class _2855使数组成为递增数组的最少右移次数 {
    class Solution {
        public int minimumRightShifts(List<Integer> nums) {
            int len = nums.size();
            int num = 1;
            int cut = 0;
            for(int i=1; i<len; i++){
                if(nums.get(i) > nums.get(i-1)){
                    num++;
                    continue;
                }
                cut++;
                num = 1;
                if(cut >= 2) return -1;
            }
            if(cut == 0) return 0;
            else if(nums.get(0) < nums.get(len-1)) return -1;
            return num;
        }
    }

}
